// 学科列表
const kemu = ['math', 'chinese', 'eglish', 'physics', 'chemistry', 'biology']
// 指定考试编号时，全年级全科平均分
export const pjfGradeAll = (baseValue, examNo) => {
    const scoreList = baseValue.scoreData.filter(
        (item) => +item.examNo === +examNo
    )[0].list
    // console.log(scoreList)
    return (
        scoreList.reduce((num, student) => {
            return num + kemu.reduce((n, i) => n + +student[i], 0)
        }, 0) / scoreList.length
    )
}
// 指定考试编号、指定科目，求全年级平均分
export const pjfGradeByKemu = (baseValue, examNo, kemuName) => {
    const scoreList = baseValue.scoreData.filter(
        (item) => +item.examNo === +examNo
    )[0].list
    // console.log(scoreList)
    return (
        scoreList.reduce((num, student) => {
            return num + +student[kemuName]
        }, 0) / scoreList.length
    )
}
// 指定考试编号、指定班级编号、指定科目名，求平均分
export const pjf = (baseValue, examNo, classNo, kemuName) => {
    let scoreList = baseValue.scoreData.filter(
        (item) => +item.examNo === +examNo
    )[0].list
    scoreList = scoreList.filter(
        (item) =>
            +baseValue.studentData.filter(
                (cell) => +cell.no === +item.studentNo
            )[0].classNo === +classNo
    )
    return (
        scoreList.reduce((num, student) => {
            return num + +student[kemuName]
        }, 0) / scoreList.length
    )
}

// 返回分布对象，给定最小值、最大值、间隔数
export const getObj = (min, max, space) => {
    let obj = {}
    for (let i = min; i <= max; i = i + space) {
        obj[i] = 0
    }
    return obj
}

// 得到全年级总成绩分布人数，以 25 为单位分档（750总分挡），共30挡
export const totalScoreEchartY = (baseValue, examNo) => {
    let obj = getObj(0, 750, 25)
    // console.log(obj)
    const scoreList = baseValue.scoreData.filter(
        (item) => +item.examNo === +examNo
    )[0].list
    scoreList.forEach((student) => {
        const value = kemu.reduce((num, i) => num + +student[i], 0)
        // console.log(Math.ceil(value / 5) * 5)
        const index = Math.ceil(value / 25) * 25
        // console.log(obj[index])
        obj[index] = obj[index] + 1
    })
    // console.log(Object.values(obj))
    return Object.values(obj)
}

// 得到全年级分科成绩分布人数，以 5 为单位分档（150总分挡），共30挡
export const score150EchartY = (baseValue, examNo, kemuName) => {
    let obj = getObj(0, 150, 5)
    // console.log(obj)
    const scoreList = baseValue.scoreData.filter(
        (item) => +item.examNo === +examNo
    )[0].list
    scoreList.forEach((student) => {
        const value = +student[kemuName]
        // console.log(Math.ceil(value / 5) * 5)
        const index = Math.ceil(value / 5) * 5
        // console.log(obj[index])
        obj[index] = obj[index] + 1
    })
    // console.log(Object.values(obj))
    return Object.values(obj)
}
// 得到全年级分科成绩分布人数，以 5 为单位分挡（120总分挡），共24挡
export const score120EchartY = (baseValue, examNo, kemuName) => {
    let obj = getObj(0, 120, 5)
    // console.log(obj)
    const scoreList = baseValue.scoreData.filter(
        (item) => +item.examNo === +examNo
    )[0].list
    scoreList.forEach((student) => {
        const value = +student[kemuName]
        // console.log(Math.ceil(value / 5) * 5)
        const index = Math.ceil(value / 5) * 5
        // console.log(obj[index])
        obj[index] = obj[index] + 1
    })
    // console.log(Object.values(obj))
    return Object.values(obj)
}
// 得到全年级分科成绩分布人数，以 5 为单位分档（108总分挡），共22挡
export const score108EchartY = (baseValue, examNo, kemuName) => {
    let obj = getObj(0, 110, 5)
    // console.log(obj)
    const scoreList = baseValue.scoreData.filter(
        (item) => +item.examNo === +examNo
    )[0].list
    scoreList.forEach((student) => {
        const value = +student[kemuName]
        // console.log(Math.ceil(value / 5) * 5)
        const index = Math.ceil(value / 5) * 5
        // console.log(obj[index])
        obj[index] = obj[index] + 1
    })
    // console.log(Object.values(obj))
    return Object.values(obj)
}
// 得到全年级分科成绩分布人数，以 5 5为单位分档（72总分挡），共15挡
export const score72EchartY = (baseValue, examNo, kemuName) => {
    let obj = getObj(0, 75, 5)
    // console.log(obj)
    const scoreList = baseValue.scoreData.filter(
        (item) => +item.examNo === +examNo
    )[0].list
    scoreList.forEach((student) => {
        const value = +student[kemuName]
        // console.log(Math.ceil(value / 5) * 5)
        const index = Math.ceil(value / 5) * 5
        // console.log(obj[index])
        obj[index] = obj[index] + 1
    })
    // console.log(Object.values(obj))
    return Object.values(obj)
}
